package com.zutassociation.web.controller.system;

import com.zutassociation.common.core.controller.BaseController;
import com.zutassociation.common.core.domain.AjaxResult;
import com.zutassociation.common.core.page.TableDataInfo;
import com.zutassociation.common.utils.SecurityUtils;
import com.zutassociation.system.domain.Elect;
import com.zutassociation.system.service.ElectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 换届选举 信息操作处理
 *
 * @author 黄玉东
 * @version 1.0
 * @date 2021/2/25 18:03
 */

@RestController
@RequestMapping("/elect")
public class ElectController extends BaseController {

    @Autowired
    private ElectService electService;


    /**
     * 获取换届选举列表
     */
//    @PreAuthorize("@ss.hasPermi('system:elect:list')")
    @GetMapping("/list")
    public TableDataInfo list(Elect elect) {
        startPage();
        List<Elect> list = electService.selectElectList(elect);
        return getDataTable(list);
    }

    /**
     * 获取上一条换届选举列表
     */
//    @PreAuthorize("@ss.hasPermi('system:elect:query')")
    @GetMapping(value = "/getUpElect/{electId}")
    public AjaxResult getUpElect(@PathVariable("electId") Long electId) {
        return AjaxResult.success(electService.selectUpElect(electId));
    }

    /**
     * 获取下一条换届选举列表
     */
//    @PreAuthorize("@ss.hasPermi('system:elect:query')")
    @GetMapping(value = "/getNextElect/{electId}")
    public AjaxResult getNextElect(@PathVariable("electId") Long electId) {
        return AjaxResult.success(electService.selectNextElect(electId));
    }

    /**
     * 根据换届选举编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:Elect:query')")
    @GetMapping(value = "/{electId}")
    public AjaxResult getInfo(@PathVariable("electId") Long electId) {
        return AjaxResult.success(electService.selectElectById(electId));
    }

    /**
     * 新增换届选举
     */
//    @PreAuthorize("@ss.hasPermi('system:elect:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Elect elect) {
        elect.setCreateBy(SecurityUtils.getUsername());
        return toAjax(electService.insertElect(elect));
    }

    /**
     * 修改换届选举
     */
//    @PreAuthorize("@ss.hasPermi('system:elect:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Elect elect) {
        elect.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(electService.updateElect(elect));
    }

//    @PreAuthorize("@ss.hasPermi('system:elect:edit')")
    @PutMapping("updateClick")
    public AjaxResult updateClick(@Validated @RequestBody Elect elect) {
        return toAjax(electService.updateElectClick(elect));
    }

    /**
     * 删除换届选举
     */
//    @PreAuthorize("@ss.hasPermi('system:elect:remove')")
    @DeleteMapping("/{electIds}")
    public AjaxResult remove(@PathVariable Long[] electIds) {
        return toAjax(electService.deleteElectByIds(electIds));
    }

}
